#!/usr/bin/python

'''to monitor the system information '''

import psutil

def cpu_info():
    '''to monitor the cpu information '''
    a = psutil.cpu_percent()
    print("the cpu usage rate is {}%".format(a))
    if a >= 80:
        print("the cpu is vary busy")

def disk_info():
    '''to monitor the disk information '''
    disk_used = int(psutil.disk_usage('/').used/1024/1024)
    disk_free = int(psutil.disk_usage('/').free/1024/1024)
    disk_use_percent = psutil.disk_usage('/').percent
    read_io = psutil.disk_io_counters().read_count
    write_io = psutil.disk_io_counters().write_count
    print("disk used: %d M"%disk_used)
    print("disk free: %d M"%disk_free)
    print("disk use percent: {0}%".format(disk_use_percent))
    print("read io count is %d"%read_io)
    print("write io count is %d"%write_io)
    if 60 <= disk_use_percent <80:
        print("insufficient disk space")
    elif disk_use_percent >= 80:
        print("There is a serious shortage of disk space")
    if read_io > 80000 and write_io > 400000:
        print("disk is busy")

def mem_info():
    '''to monitor the memory information '''
    pv = psutil.virtual_memory()
    mem_use_percent = pv.percent
    print("mem use percent: {0}%".format(mem_use_percent))
    if 60 <= mem_use_percent < 80:
        print("run out of memory")
    elif mem_use_percent >= 80:
        print("undermemory")

def main():
    while 1:
        print("#"*20)
        print("1.look cpu info")
        print("2.look disk info")
        print("3.look mem info")
        print("4.exit")
        option = input("please input your choice:")
        opt = {"1":cpu_info,"2":disk_info,"3":mem_info,"4":exit}
        if option in opt:
            opt.get(option)()
        else:
            print("please input 1-4")

main()
